#pragma once
#include "uv.h"

class UvClient
{
public:
	UvClient(uv_tcp_t* handle, int nBufSize);
	virtual ~UvClient();
	uv_tcp_t* GetHandle() const;
	long GetConnectedTime() const;
	char* GetRecvBuf() const;
	int GetBufSize() const;
	int GetState() const;
	void StartRead();
	void Close();
	bool Write(const char* pData, int length, bool bCopy, bool bDelete);
	virtual void OnRead(char* pData, int length) = 0;
protected:
	static void OnClose(uv_handle_t* handle);
	static void OnWritten(uv_write_t* write, int status);
	static void OnRead(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf);
protected:
	uv_tcp_t* m_pHandle;
	long m_ConnectTime;
	char* m_pRecvBuf;
	int m_nBufSize;
	int m_nState;
};
